﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace WINADM.Server.WMI
{
    public class Win32EventLog
    {
        string _CategoryString;

        public string CategoryString
        {
            get { return _CategoryString; }
            set { _CategoryString = value; }
        }
        UInt32? _EventIdentifier;

        public UInt32? EventIdentifier
        {
            get { return _EventIdentifier; }
            set { _EventIdentifier = value; }
        }
        byte? _EventType;

        public byte? EventType
        {
            get { return _EventType; }
            set { _EventType = value; }
        }
        string _Logfile;

        public string Logfile
        {
            get { return _Logfile; }
            set { _Logfile = value; }
        }
        string _Message;

        public string Message
        {
            get { return _Message; }
            set { _Message = value; }
        }
        UInt32? _RecordNumber;

        public UInt32? RecordNumber
        {
            get { return _RecordNumber; }
            set { _RecordNumber = value; }
        }
        string _SourceName;

        public string SourceName
        {
            get { return _SourceName; }
            set { _SourceName = value; }
        }
        DateTime? _TimeGenerated;

        public DateTime? TimeGenerated
        {
            get { return _TimeGenerated; }
            set { _TimeGenerated = value; }
        }
        DateTime? _TimeWritten;

        public DateTime? TimeWritten
        {
            get { return _TimeWritten; }
            set { _TimeWritten = value; }
        }
        string _User;

        public string User
        {
            get { return _User; }
            set { _User = value; }
        }

        public Win32EventLog()
        {
        }

        public Win32EventLog(ManagementObject wmiWin32EventLogObject)
        {
            this._CategoryString = (string)wmiWin32EventLogObject["CategoryString"];
            this._EventIdentifier = (uint?)wmiWin32EventLogObject["EventIdentifier"];

            if(wmiWin32EventLogObject["EventType"] != null)
            this._EventType =Convert.ToByte(wmiWin32EventLogObject["EventType"].ToString());

            this._Logfile = (string)wmiWin32EventLogObject["Logfile"];
            this._Message = (string)wmiWin32EventLogObject["Message"];
            this._RecordNumber = (uint?)wmiWin32EventLogObject["RecordNumber"];
            this.SourceName = (string)wmiWin32EventLogObject["SourceName"];
            this._TimeGenerated = WMIUtility.ConvertDmtfToDateTime(wmiWin32EventLogObject["TimeGenerated"]);
            this._TimeWritten = WMIUtility.ConvertDmtfToDateTime(wmiWin32EventLogObject["TimeWritten"]);
            this._User = (string)wmiWin32EventLogObject["User"];
        }
    }
}
